import { header } from "./header.js"
class Daohang {
    constructor() {
        this.init();
    }
}
$.extend(Daohang.prototype, {
    init: function () {
        this.headerP = $(".header_p")
        this.menuList = $(".menu_list")
        // 一级菜单
        this.menuList.on("mouseenter", ".cate_link", this.showDropDown.bind(this))
        this.menuList.on("mouseleave", ".cate_link", this.hideDropDown.bind(this))
        this.menuList.on("mouseenter", ".nav_dropdown", this.holdDropDown.bind(this))
        this.menuList.on("mouseleave", ".nav_dropdown", this.hideDropDownTwo.bind(this))
        this.timer = null;
    },
    //显示下拉框
    showDropDown: function (evt) {
        var e = evt || event;
        var target = e.target || e.srcElement;
        $(target).next().attr({ style: "z-index:9;height:357px;box-shadow:rgba(0,0,0,0.15) 0px 30px 34px -15px" });
        this.scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
        header.changeColor();
    },
    // 隐藏
    hideDropDown: function (evt) {
        var e = evt || event;
        var target = e.target || e.srcElement;
        this.timer = setTimeout(function () {
            $(target).next().attr({ style: "z-index: -1; height: 0px; box-shadow: none;" });
            this.scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
        }, 300)
        if (this.scrollTop == 0) {
            header.colorBack();
        }
    },
    hideDropDownTwo:function(evt){
        var e = evt || event;
        var target = e.target || e.srcElement;
        $(target).parents(".nav_dropdown").attr({ style: "z-index: -1; height: 0px; box-shadow: none;" });
        this.scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
        if (this.scrollTop == 0) {
            header.colorBack();
        }
    },
    holdDropDown: function (evt) {
        var e = evt || event;
        var target = e.target || e.srcElement;
        clearTimeout(this.timer)
        header.changeColor();
        $(target).attr({ style: "z-index:9;height:357px;box-shadow:rgba(0,0,0,0.15) 0px 30px 34px -15px" })
    }


})
var daohang = new Daohang();
export { daohang }